class Single {

    constructor(){
        if(Single._instance){
            return Single._instance
        }
        Single._instance = this;
    }

    getInstance(){
        if(!Single._instance){
            return new Single()
        } else {
            return Single._instance
        }
    }
}


class EventEmitter {
    constructor(){
        this.map = new Map()
    }
    on(event, cb){
        let list = this.map.get(event) || []
        list.push(cb)
        this.map.set(event, list)
    }
    emit(event, ...args){
        let list = this.map.get(event) || []
        list.forEach((fn) => fn(...args))
    }
    off(event, cb){
        let list = this.map.get(event) || []
        list = list.filter(fn => fn !== cb)
        this.map.set(event, list)
    }
    once(event, cb){
        let wrapperFn = (...args) => {
            cb.call(this, ...args)
            this.off(event, wrapperFn)
        }
        this.on(event, wrapperFn)

    }
}